package com.hexorld.core;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;

import com.hexorld.utils.Position;

public class StatusView extends HVisualObject {
	protected final int HP_BAR_WIDTH = 100;
	protected final int HP_BAR_HEIGHT = 16;
	protected final int SP_BAR_WIDTH = 100;
	protected final int SP_BAR_HEIGHT = 16;
	
	protected ObjectStatus mStatus;
	protected BasicBar mHpBar;
	protected BasicBar mSpBar;
	public StatusView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	public StatusView(Context context, ObjectStatus status){
		super(context);
		mStatus = status;
		initViews();
	}

	protected void initViews(){
		prepareBars();
	}
	
	@Override
	public void draw(Canvas canvas) {
		if(mStatus == null)
			return;
		drawBasicBars(canvas);
	}

	public void setPosition(int x, int y){
		super.setPosition(x, y);
		if(mHpBar != null)
			mHpBar.setPosition(x, y);
		if(mSpBar != null)
			mSpBar.setPosition(x, y + HP_BAR_HEIGHT);
	}
	/*
	 * currently, this view has hp&sp bar only
	 */
	private void prepareBars(){
		mHpBar = new DColorBar(mContext, HP_BAR_WIDTH, HP_BAR_HEIGHT, mStatus.maxHp, new Position(this.position.x, this.position.y));
		mHpBar.setValue(mStatus.hp);
		((DColorBar)mHpBar).setColor(0xffff0000, 0xff00ff00);
		mHpBar.displayValue(true);
		
		mSpBar = new BasicBar(mContext, SP_BAR_WIDTH, SP_BAR_HEIGHT, mStatus.maxSp, new Position(this.position.x, this.position.y + HP_BAR_HEIGHT));
		mSpBar.setValue(mStatus.sp);
		mSpBar.setBarColor(Color.BLUE);
		mSpBar.displayValue(true);
	}
	
	private void drawBasicBars(Canvas canvas){
		mHpBar.update(canvas);
		mSpBar.update(canvas);
	}

	@Override
	public void update(long timeElapsed) {
		// TODO Auto-generated method stub
		
	}

}
